﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

namespace WebSite.cn
{
    public partial class index : BasePage
    {
        // Fields

        public string hotmsg1 = "";
        public string hotmsg2 = "";
        public string hotmsg3 = "";
        public string hotmsg4 = "";
        public string hotpic1 = "";
        public string hotpic2 = "";
        public string hotpic3 = "";
        public string hotpic4 = "";
        public string hottitle1 = "";
        public string hottitle2 = "";
        public string hottitle3 = "";
        public string hottitle4 = "";
        public string imgAlt = "";
        public string imgLink = "";
        public string imgtext = "";
        public string imgUrl = "";
        public string newsmsg = "";
        public string peipro = "";
        public string pinpai = "";
        public string topic = "";

        public string imgNumber = "";

        // Methods
        private void Bind()
        {
            DataTable table = SQLAccess.GreatDs("select * from DB_Flash where modelid=" + fun.banner("") + " and isnull(shopid,0) =0 order by flashid asc").Tables[0];
            if (table.Rows.Count > 0)
            {
                string sFlashUrl = string.Empty;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (i < table.Rows.Count )
                    {
                        if (table.Rows[i]["flashurl"] == null || table.Rows[i]["flashurl"].ToString() == "")
                        {
                            sFlashUrl = "#";
                        }
                        else
                        {
                            sFlashUrl = table.Rows[i]["flashurl"].ToString() ;
                        }

                        this.imgLink = this.imgLink + " <li><a href='" + sFlashUrl + "'><img src='../uploadfile/" + table.Rows[i]["flashpic"].ToString().Replace(@"\", "/") + "'/></a></li>";
                        this.imgNumber = this.imgNumber + "<li>" + (i+1).ToString() + "</li>"; 
                    }
                    //else if (i == (table.Rows.Count - 1))
                    //{
                    //    this.imgLink = this.imgLink + " <li><a href='" + "../uploadfile/" + table.Rows[i]["flashpic"].ToString().Replace(@"\", "/") + "'><img src='" + table.Rows[i]["flashurl"].ToString() + "'/></a></li>";
                    //    this.imgNumber = this.imgNumber + "<li>" + (i+1).ToString() + "</li>"; 
                    //}
                }
            }
            table = SQLAccess.GreatDs(string.Concat(new object[] { "select top ", Convert.ToInt32(info.info1("", "homeshownnum")), " newsid,newsname,typeid from DB_News where typeid in(", re.returnnewstype( "2", "0"), ") and visible=1 and isnew=1 order by newsorder,updatetime desc" })).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    string newsmsg = this.newsmsg;
                    this.newsmsg = newsmsg + "<li><a href='news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString() + "' title='" + row["newsname"].ToString() + "'>" + fun.Left(row["newsname"].ToString(), 13) + "..</a></li>";
                }
            }
            string sql = "select pic,shuxiname from DB_Shuxintype where shuxinid=1";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hotpic1 = table.Rows[0][0].ToString();
                this.hottitle1 = table.Rows[0][1].ToString();
            }
            int num2 = Convert.ToInt32(info.info1("", "shopnum2"));
            int num3 = Convert.ToInt32(info.info1("", "homeshowpnum1"));
            int num4 = Convert.ToInt32(info.info1("", "homeshowpnum2"));
            int num5 = Convert.ToInt32(info.info1("", "homeshowpnum3"));
            table = SQLAccess.GreatDs("select top " + num2 + " proid,proname,proprice1,proprice3,propic2,typeid,proisnew2,proisnew3,proisnew4 from DB_Shoppro where visible=1 and proisshow=1 and proisnew1=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num6 = 0;
                foreach (DataRow row2 in table.Rows)
                {
                    string sSid = string.Empty;
                    if (row2["proisnew2"].ToString().ToLower() == "true")
                    {
                        sSid = "2";
                    }
                    else if (row2["proisnew3"].ToString().ToLower() == "true")
                    {
                        sSid = "3";
                    }
                    else if (row2["proisnew4"].ToString().ToLower() == "true")
                    {
                        sSid = "4";
                    }
                    else
                    {
                        sSid = "1";
                    }

                    this.hotmsg1 = this.hotmsg1 + "<td valign='top'>";
                    string str4 = this.hotmsg1;
                    this.hotmsg1 = str4 + "<p><a href='products_details.aspx?pid=" + row2["proid"].ToString() + "&sid=" + sSid + "'><img src=../uploadfile/product/" + row2["propic2"].ToString() + " width='110px' /></a></p>";
                    this.hotmsg1 = this.hotmsg1 + "<ul>";
                    string str5 = this.hotmsg1;
                    this.hotmsg1 = str5 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row2["proid"].ToString() + "&sid=" + sSid + "' title='" + row2["proname"].ToString() + "'>" + fun.Left(row2["proname"].ToString(), 15) + "</a></li>";
                    string sPriceName = "";
                    if (row2["proisnew3"].ToString().ToLower() == "true") {sPriceName = "零售价:"; }else{ sPriceName = "兑换价";}
                    this.hotmsg1 = this.hotmsg1 + "<li style='height:18px' class='text_red'>" + sPriceName + string.Format("{0:f}", row2["proprice1"]) + "</li>";
                  //  this.hotmsg1 = this.hotmsg1 + "<li class='text03'>市场价:" + string.Format("{0:f}", row2["proprice3"]) + "</li>";
                 
                    this.hotmsg1 = this.hotmsg1 + "</ul>";
                    this.hotmsg1 = this.hotmsg1 + "</td>";
                    num6++;
                    if (num6 >= num2)
                    {
                        break;
                    }
                    if ((num6 % 5) == 0)
                    {

                        this.hotmsg1 = this.hotmsg1 + "</tr><tr>";

                    }

                }
            }
            sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=2";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hottitle2 = table.Rows[0][0].ToString();
                this.hotpic2 = table.Rows[0][1].ToString();
            }
            table = SQLAccess.GreatDs("select top " + num3 + " proid,proname,proprice1,proprice3,propic2,typeid from DB_Shoppro where visible=1 and proisshow=1 and proisnew2=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num7 = 0;
                foreach (DataRow row3 in table.Rows)
                {
                    this.hotmsg2 = this.hotmsg2 + "<td valign='top'>";
                    string str6 = this.hotmsg2;
                    this.hotmsg2 = str6 + "<p><a href='products_details.aspx?pid=" + row3["proid"].ToString() + "&sid=2'><img src=../uploadfile/product/" + row3["propic2"].ToString() + " width='110px' /></a></p>";
                    this.hotmsg2 = this.hotmsg2 + "<ul>";
                    string str7 = this.hotmsg2;
                    this.hotmsg2 = str7 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row3["proid"].ToString() + "&sid=2' title='" + row3["proname"].ToString() + "'>" + fun.Left(row3["proname"].ToString(), 15) + "</a></li>";

                    this.hotmsg2 = this.hotmsg2 + "<li style='height:18px' class='text_red'>兑换价:" + string.Format("{0:f}", row3["proprice1"]) + "</li>"; 
                  // this.hotmsg2 = this.hotmsg2 + "<li class='text03'>市场价:" + string.Format("{0:f}", row3["proprice3"]) + "</li>";
                   
                    this.hotmsg2 = this.hotmsg2 + "</ul>";
                    this.hotmsg2 = this.hotmsg2 + "</td>";
                    num7++;
                    if (num7 >= num3)
                    {
                        break;
                    }
                    if ((num7 % 5) == 0)
                    {
                        
                        this.hotmsg2 = this.hotmsg2 + "</tr><tr>";
                        
                    }
                }
            }
            sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=3";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hottitle3 = table.Rows[0][0].ToString();
                this.hotpic3 = table.Rows[0][1].ToString();
            }
            table = SQLAccess.GreatDs("select top " + num4 + " proid,proname,proprice1,proprice3,propic2,typeid from DB_Shoppro where visible=1 and proisshow=1 and proisnew3=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num8 = 0;
                foreach (DataRow row4 in table.Rows)
                {
                    this.hotmsg3 = this.hotmsg3 + "<td valign='top'>";
                    string str8 = this.hotmsg3;
                    this.hotmsg3 = str8 + "<p><a href='products_details.aspx?pid=" + row4["proid"].ToString() + "&sid=3'><img src=../uploadfile/product/" + row4["propic2"].ToString() + " width='110px'  /></a></p>";
                    this.hotmsg3 = this.hotmsg3 + "<ul>";
                    string str9 = this.hotmsg3;
                    this.hotmsg3 = str9 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row4["proid"].ToString() + "&sid=3' title='" + row4["proname"].ToString() + "'>" + fun.Left(row4["proname"].ToString(), 15) + "</a></li>";

                    this.hotmsg3 = this.hotmsg3 + "<li style='height:18px' class='text_red'>零售价:" + string.Format("{0:f}", row4["proprice1"]) + "</li>"; 
                //    this.hotmsg3 = this.hotmsg3 + "<li class='text03'>市场价:" + string.Format("{0:f}", row4["proprice3"]) + "</li>";
                  
                    this.hotmsg3 = this.hotmsg3 + "</ul>";
                    this.hotmsg3 = this.hotmsg3 + "</td>";
                    num8++;
                    if (num8 >= num4)
                    {
                        break;
                    }
                    if ((num8 % 5) == 0)
                    {
                        this.hotmsg3 = this.hotmsg3 + "</tr><tr>";
                    }
                }
            }
            sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=4";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hottitle4 = table.Rows[0][0].ToString();
                this.hotpic4 = table.Rows[0][1].ToString();
            }
            table = SQLAccess.GreatDs("select top " + num5 + " proid,proname,proprice1,proprice3,propic2,typeid from DB_Shoppro where visible=1 and proisshow=1 and proisnew4=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num9 = 0;
                foreach (DataRow row5 in table.Rows)
                {
                    this.hotmsg4 = this.hotmsg4 + "<td valign='top'>";
                    string str10 = this.hotmsg4;
                    this.hotmsg4 = str10 + "<p><a href='products_details.aspx?pid=" + row5["proid"].ToString() + "&sid=4'><img src=../uploadfile/product/" + row5["propic2"].ToString() + " width='110px'  /></a></p>";
                    this.hotmsg4 = this.hotmsg4 + "<ul>";
                    string str11 = this.hotmsg4;
                    this.hotmsg4 = str11 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row5["proid"].ToString() + "&sid=4' title='" + row5["proname"].ToString() + "'>" + fun.Left(row5["proname"].ToString(), 15) + "</a></li>";
                    this.hotmsg4 = this.hotmsg4 + "<li style='height:18px' class='text_red'>兑换价:" + string.Format("{0:f}", row5["proprice1"]) + "</li>";
                   // this.hotmsg4 = this.hotmsg4 + "<li class='text03'>市场价:" + string.Format("{0:f}", row5["proprice3"]) + "</li>";
                  
                    this.hotmsg4 = this.hotmsg4 + "</ul>";
                    this.hotmsg4 = this.hotmsg4 + "</td>";
                    num9++;
                    if (num9 >= num5)
                    {
                        break;
                    }
                    if ((num9 % 5) == 0)
                    {
                        this.hotmsg4 = this.hotmsg4 + "</tr><tr>";
                    }
                }
            }
            string str2 = "select topicid,pic,picurl from DB_topic where visible=1 and isnew=1 and location=1 order by topicorder asc";
            DataTable table2 = SQLAccess.GreatDs(str2).Tables[0];
            if (table2.Rows.Count > 0)
            {
                string topic = this.topic;
                this.topic = topic + "<a href='" + table2.Rows[0]["picurl"].ToString() + "?tid=" + table2.Rows[0]["topicid"].ToString() + "' target='_blank'><img src='" + table2.Rows[0]["pic"].ToString() + "' border='0' /></a>";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Session["backHref"] = Request.Url.PathAndQuery;
            if (!base.IsPostBack)
            {
              //  this.browesProduct1.ClientIP = this.ClientIP;
                this.Bind();
            }
        }

    }
}